//
//  CustomerController.m
//  电影er
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomerController.h"
#import "CustModel.h"
#import "CustViewCell.h"
#import "CustHight.h"
#import "CusendViewController.h"
@interface CustomerController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *muarray;

@end

@implementation CustomerController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.muarray = [[NSMutableArray alloc]init];
    

        self.navigationItem.title = @"影院";
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.41f green:0.61f blue:0.68f alpha:1.00f];
        self.navigationController.navigationBar.titleTextAttributes=@{
                                                                      NSForegroundColorAttributeName:[UIColor blackColor],
                                                                      NSFontAttributeName:[UIFont boldSystemFontOfSize:20]
                                                                      
                                                                      };
        
        self.automaticallyAdjustsScrollViewInsets =NO;
        
    
    [self creactTabview];
    [self shujufenxi];
    
}
-(void)creactTabview{
    
    UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];
     tableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tableview];
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.rowHeight = 150;
    [tableview registerClass:[CustViewCell class] forCellReuseIdentifier:@"ccq"];
    
    
    }

-(void)shujufenxi{
    
    NSString *str = [[NSBundle mainBundle]pathForResource:@"cinemalist" ofType:@".txt"];
    NSData *data = [NSData dataWithContentsOfFile:str];
    NSError *error = nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    NSDictionary *dic2 = [dic objectForKey:@"result"];
    NSArray *array = [dic2 valueForKey:@"data"];
    for (NSDictionary *dict in array) {
        CustModel *mode = [[CustModel alloc]init];
        [mode setValuesForKeysWithDictionary:dict];
        [self.muarray addObject:mode];
        [mode release];
        
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.muarray.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CustViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"ccq"];
    CustModel  *mode = [self.muarray objectAtIndex:indexPath.row];
    cell.cmodel = mode;
    return cell;
    
    
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    CustModel *mode = [self.muarray objectAtIndex: indexPath.row];
    return [CustHight heightWithTime:mode.cinemaName]+150;


}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CusendViewController *cevc = [[CusendViewController alloc]init];
    self.cumodel = [self.muarray objectAtIndex:indexPath.row];
    cevc.cumodel = self.cumodel;
    
    [self.navigationController pushViewController:cevc animated:YES];
    
    
}


@end
